package org.example.system.repository;

import org.example.commons.entity.SysAdmin;
import org.example.commons.entity.SysFeedback;
import org.example.commons.entity.SysHealthStatus;
import org.example.commons.entity.SysUser;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * 用户反馈数据层
 *
 * @author bothin
 */
@Repository
public interface SysFeedbackRepository extends JpaRepository<SysFeedback,Long> {
    List<SysFeedback> findByFeedbackIdIn(Long[] ids);
    /**
     * 条件查询
     * @return
     */
    @Query(value = "select f from SysFeedback f " +
            "where f.userName like :name and f.content like :content " +
            " and ( :#{#dates[0]} IS NULL OR :#{#dates[1]} IS NULL " +
            " OR f.createTime between :#{#dates[0]} and :#{#dates[1]})" )
    Page<SysFeedback> searchList(String name, String content, Date[] dates, Pageable pageable);

    @Query(value = "SELECT * FROM sys_feedback  where DATE_SUB(CURDATE(), INTERVAL ? DAY) >= date(create_time)",nativeQuery =true)
    List<SysFeedback>  findLastFeedback(Integer days);
}
